|
|
 |
|
|
|
|
Private TheGrid As Grid3d ' The display grid.
Private NumPts As Integer ' # actual data values. Private Data() As Point3D ' Actual data values. |
|
|
|
|
|
|
|
|
You can use a couple of methods to generate grid data using the incomplete data values you have available. The first method is to simply use the data value that is closest to the position you need. For each location (a, b) where you want a data value in the grid, find the data point (x, y, z) where (a x)2 + (b z)2 is smallest. Use that data point's Y value for the grid value at (a, b). |
|
|
|
|
|
|
|
|
The NearestPoint subroutine shown in the following code simply looks through the array of data values to find the one that is closest to a given point. For very large data sets, you could make this search faster using the quadtree techniques described in Chapter 12, Two-Dimensional Transformations. |
|
|
|
 |
|
|
|
|
' Return the index of the closest data point. Private Function NearestPoint(ByVal X As Single, _
ByVal Z As Single) As Integer
Dim i As Integer
Dim best_i As Integer
Dim best_dist2 As Single
Dim diffx As Single
Dim diffz As Single
Dim dist2 As Single
' Start with no data point. best_i = 0
best_dist2 = 1E+30
' See which points are closer. For i = 1 To NumPts
' See if this point is closer than the ones ' already chosen. diffx = X - Data(i).coord(1)
diffz = Z - Data(i).coord(3)
dist2 = diffx * diffx + diffz * diffz
If dist2 < best_dist2 Then
best_i = i
best_dist2 = dist2
End If
Next i
NearestPoint = best_i
End Function |
|
|
|
|
|
|
|
|
The InitializeGrid subroutine provided by the SparseGrid3d class uses NearestPoint to set points in the display grid. First, it examines the data to find the largest and smallest X and Z values. It creates the display grid object and gives it appropriate data bounds. |
|
|
|
|
|